// pages/checkin/index.js
Page({
  data: {
    userInfo: {
      level: 15,
      experience: 75,
      points: 1280,
      checkinDays: 7,
      maxCheckinDays: 7
    },
    checkinStatus: {
      today: false,
      streak: 3,
      totalDays: 28
    },
    rewards: [
      { day: 1, name: "签到奖励", points: 10, claimed: true },
      { day: 2, name: "连续签到", points: 15, claimed: true },
      { day: 3, name: "坚持打卡", points: 20, claimed: true },
      { day: 4, name: "今日奖励", points: 25, claimed: false },
      { day: 5, name: "周末福利", points: 30, claimed: false },
      { day: 6, name: "一周坚持", points: 50, claimed: false },
      { day: 7, name: "满勤奖励", points: 100, claimed: false }
    ],
    monthlyStats: [
      { week: 1, days: 7, status: "completed" },
      { week: 2, days: 5, status: "partial" },
      { week: 3, days: 7, status: "completed" },
      { week: 4, days: 3, status: "partial" }
    ]
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '每日签到'
    })
  },

  onCheckinTap: function() {
    if (this.data.checkinStatus.today) {
      wx.showToast({
        title: '今日已签到',
        icon: 'none'
      })
      return
    }

    wx.showModal({
      title: '确认签到',
      content: '确定要签到吗？签到可获得积分奖励！',
      success: function(res) {
        if (res.confirm) {
          wx.showLoading({
            title: '签到中...'
          })
          
          setTimeout(function() {
            wx.hideLoading()
            wx.showToast({
              title: '签到成功！获得25积分',
              icon: 'success'
            })
            
            // 更新签到状态
            this.setData({
              'checkinStatus.today': true,
              'checkinStatus.streak': this.data.checkinStatus.streak + 1,
              'checkinStatus.totalDays': this.data.checkinStatus.totalDays + 1,
              'userInfo.points': this.data.userInfo.points + 25
            })
          }.bind(this), 1000)
        }
      }.bind(this)
    })
  },

  onRewardTap: function(e) {
    const reward = e.currentTarget.dataset.reward
    
    if (reward.claimed) {
      wx.showToast({
        title: '奖励已领取',
        icon: 'none'
      })
      return
    }
    
    wx.showModal({
      title: '领取奖励',
      content: `确定要领取"${reward.name}"吗？\n奖励：${reward.points}积分`,
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '奖励领取成功',
            icon: 'success'
          })
        }
      }
    })
  },

  onHistoryTap: function() {
    wx.showModal({
      title: '签到历史',
      content: '查看详细的签到记录和统计信息',
      showCancel: true,
      cancelText: '关闭',
      confirmText: '查看详情',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '历史记录功能开发中',
            icon: 'none'
          })
        }
      }
    })
  }
})
